package components.plugins.effects
{
	import UIUtils.uif_util;
	
	import flash.display.BitmapData;
	import flash.display.BlendMode;
	import flash.filters.ConvolutionFilter;
	import flash.geom.ColorTransform;
	import flash.geom.Point;

	public class clte_emboss extends clt_baseEffect {
		
		protected var _filter: ConvolutionFilter;
		public function clte_emboss(a_params:Object) {
			super(uif_util.unionObj({
				alpha		: 0.5,
				matrix		: [0, 0, 0,
						   0, 1, 0,
						   0, 0, 0],
				divisor		: 1,
				invert		: false,
				colorOffset	: 0
			}, a_params));
			updateFilter();
		}
		
		override public function execute(bitmapData: BitmapData):void {
			var a_tmp	: BitmapData = copyBD(bitmapData);
			var ct		: ColorTransform;
			
			if (params.invert) ct = new ColorTransform(-1, -1, -1, params.alpha, 0xFF + params.colorOffset, 0xFF + params.colorOffset, 0xFF + params.colorOffset);
			else ct = new ColorTransform(1, 1, 1, params.alpha, params.colorOffset, params.colorOffset, params.colorOffset );
			a_tmp.applyFilter(bitmapData, bitmapData.rect, new Point(), _filter);
			bitmapData.draw(a_tmp, null, ct, blendMode);
			a_tmp.dispose();
		}
		
		protected function updateFilter(): void {
			var m_size: int = Math.sqrt(params.matrix.length);
			_filter = new ConvolutionFilter(m_size, m_size, params.matrix, params.divisor);
		}
		
		override public function incValue1():void {
			params.alpha = changeValue(params.alpha, 0.1, 1);
		}
		
		override protected function getParamName():Array {
			return [
				locale.ALPHA,
				'','',
				locale.BLENDMODE
			];
		}
		
		override protected function getValues():Array {
			return [
				params.alpha * 100,
				0, 0,
				blendMode100
			];
		}
		
		override protected function setValues(a_set:Array):void {
			params.alpha  = a_set[0] * .01;
			super.setValues(a_set);
		}
	}
}